import os

def func(year, quarter):
    time_suffix = f'_{year}q{quarter}'
    month1 = (quarter - 1) * 3 + 1
    month2 = (quarter - 1) * 3 + 2
    month3 = (quarter - 1) * 3 + 3

    subject_name = '出入境'
    file_path = subject_name + '-模板.sql'
    output_dir = './output'
    output_path = output_dir + '/' + subject_name + time_suffix + '.sql'
    replace_dict = {
        "{{year}}": str(year),
        "{{quarter}}": str(quarter),
        "{{month1}}": f"{month1:02d}",
        "{{month2}}": f"{month2:02d}",
        "{{month3}}": f"{month3:02d}"
    }

    os.makedirs(output_dir, exist_ok=True)

    # 读取文件内容并替换
    with open(file_path, 'r', encoding='utf-8') as f:
        content = f.read()

    # 替换指定内容
    for k, v in replace_dict.items():
        print(f"{k} --> {v}")
        content = content.replace(k, v)

    with open(output_path, 'w', encoding='utf-8') as f:
        f.write(content)

    print("替换完成，输出写入", output_path)


if __name__ == '__main__':
    my_year_list = [2023, 2024]
    for my_year in my_year_list:
        for my_quarter in range(1, 5):
            func(my_year, my_quarter)